
const todoCountName = 'todoCount'
const doneCountName = 'doneCount'
const toReadCountName = 'toReadCount'
const toReadPostsChangeLogCountName = 'toReadPostsChangeLog'
const toNewsName = 'toNews'

const messageInfo = {
    namespaced: true,
    state: {
        // 待办事项总数
        todoCount: 0,
        // 已办事项总数
        doneCount: 0,
        // 待处理总数
        toReadCount: 0,
        // 岗位变更日志
        toReadPostsChangeLog: 0,
        // 新闻数量
        toNewsCount: 0,
    },
    getters: {
        GET_TODOCOUNT(state) {
            return state.todoCount || sessionStorage.getItem(todoCountName)
        },
        GET_DONECOUNT(state) {
            return state.doneCount || sessionStorage.getItem(doneCountName)
        },
        GET_TOREADCOUNT(state) {
            return state.toReadCount || sessionStorage.getItem(toReadCountName)
        },
        GET_TOREADPOSTSCHANGELOGCOUNT(state) {
            return state.toReadPostsChangeLog || sessionStorage.getItem(toReadPostsChangeLogCountName)
        },
        GET_TONEWSCOUNT(state) {
            return state.toNewsCount || sessionStorage.getItem(toNewsName)
        },
    },
    mutations: {
        SET_TODOCOUNT(state, todoCount) {
            state.todoCount = todoCount
            sessionStorage.setItem(todoCountName, todoCount)
        },
        SET_DONECOUNT(state, doneCount) {
            state.doneCount = doneCount
            sessionStorage.setItem(doneCountName, doneCount)
        },
        SET_TOREADCOUNT(state, toReadCount) {
            state.toReadCount = toReadCount
            sessionStorage.setItem(toReadCountName, toReadCount)
        },
        REMOVE_MESSAGE_COUNT(state) {
            state.todoCount = 0
            state.doneCount = 0
            state.toReadCount = 0
            sessionStorage.removeItem(todoCountName)
            sessionStorage.removeItem(doneCountName)
            sessionStorage.removeItem(toReadCountName)
        },
        SET_TOREADPOSTSCHANGELOGCOUNT(state, toReadPostsChangeLog) {
            state.toReadPostsChangeLog = toReadPostsChangeLog
            sessionStorage.setItem(toReadPostsChangeLogCountName, toReadPostsChangeLog)
        },
        REMOVE_POSTSCHANGELOG_COUNT(state) {
            state.toReadPostsChangeLog = 0
            sessionStorage.removeItem(toReadPostsChangeLog)
        },
        /**
         * @description: 
         * @param {Object} state：vuex基础数据
         * @param {Number,String} toNewsCount：新闻数量
         */
        SET_TONEWSCOUNT(state, toNewsCount) {
            state.toNewsCount = toNewsCount
            sessionStorage.setItem(toNewsName, toNewsCount)
        },
        /**
         * @description: 重置新闻数量
         * @param {*} state：vuex基础数据
         */
        REMOVE_NEWS_COUNT(state) {
            state.toNewsCount = 0
            sessionStorage.removeItem(toNewsName)
        },
    }
}

export default messageInfo